﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using EShop.BLL;

namespace EShop.Client
{
    public partial class frmShopDailyReport : frmBase
    {
        public frmShopDailyReport()
        {
            InitializeComponent();
        }

        private void frmShopDailyReport_Load(object sender, EventArgs e)
        {
            //Init(null);
            dtDateTarget_ValueChanged(sender, e);
        }

        private void Init(string strEmployeeID)
        {
            DataTable selledDetail = new DataTable();
            decimal saleroom = 0;
            ShopReportBLL oShopReportBLL = new ShopReportBLL();
            oShopReportBLL.DailySelledReport(dtDateTarget.Value, out saleroom, out selledDetail, strEmployeeID);
            this.lblRealAmount.Text = saleroom.ToString();
            int iRowCount = selledDetail.Rows.Count;
            dgvResult.Rows.Clear();
            if (iRowCount <= 0) return;
            int index = -1;
            for (int i = 0; i < iRowCount; i++)
            {
                index = dgvResult.Rows.Add();
                dgvResult.Rows[index].Cells["Barcode"].Value = selledDetail.Rows[i]["Barcode"];
                dgvResult.Rows[index].Cells["MerchandiseName"].Value = selledDetail.Rows[i]["MerchandiseName"];
                dgvResult.Rows[index].Cells["SellNum"].Value = selledDetail.Rows[i]["BuyNumber"];
            }
        }

        private void dtDateTarget_ValueChanged(object sender, EventArgs e)
        {

            Dictionary<object, object> o = new ShopReportBLL().GetSelledEmployee(dtDateTarget.Value);
            this.cbxEmployee.Items.Clear();
            this.cbxEmployee.Items.Add("所有员工");
            foreach (KeyValuePair<object, object> item in o)
            {
                this.cbxEmployee.Items.Add(new EmployeeItems(item.Key, item.Value));
            }
            this.cbxEmployee.SelectedIndex = 0;
        }

        private void cbxEmployee_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbxEmployee.SelectedIndex == 0)
            {
                Init(null);
            }
            else
            {
                Init(((cbxEmployee.SelectedItem) as EmployeeItems).EmployeeID.ToString());
            }
        }

        class EmployeeItems
        {
            private object oEmployeeID;

            public object EmployeeID
            {
                get { return oEmployeeID; }
                set { oEmployeeID = value; }
            }

            private object oFullName;

            public object FullName
            {
                get { return oFullName; }
                set { oFullName = value; }
            }

            public EmployeeItems(object oEmployeeID, object oFullName)
            {
                this.oEmployeeID = oEmployeeID;
                this.oFullName = oFullName;
            }

            public override string ToString()
            {
                return this.oFullName.ToString();
            }
            
        }

        private void btnDone_Click(object sender, EventArgs e)
        {
            Close();
        }


    }
}
